/**
 * 详情页面的js
 */
function submitComment() {
    if ($user.id=='undefined' || $user.id==0 || $user.id==null) {
        alert('请登录后发表评论!');
        window.location.href = '/user/login';
        return false;
    };
    var content = $('#reply_body').val();
    if (content=='' || content==null) {
        alert('必须填写内容!');
        return false;
    }
    var pid = $('#pid').val();
    if (pid=='undefined' || pid==''|| pid==0 || pid==null) {
        alert('文章不存在!');
        return false;
    };
    $.ajax({
        url:'/p/createComment',
        dataType:'json',
        type: "POST",
        data: "content="+content+"&pid="+pid,
        success:function(request){
            if (request.error != "ok") {
                alert(request.error);
                return false;
            } else {
                $('#allComments').prepend(request.result);
                return false;
            }
        },
    });
}
$(function() {
    $('#subComment').on('click', function(){
        submitComment();
        return false;
    });
});
